<template>
  <div>
    <PartInfo ref="partInfo" type="edit" :partInfoRow="partInfoRow" @getEditPartInfo="getEditPartInfo" @getAddPartInfo="getAddPartInfo" />
    <div class="btnWrap">
      <el-button @click="$emit('cancel')">取 消</el-button>
      <el-button type="primary" @click="confirmBtnClick">确 定</el-button>
    </div>
    <!-- 配件库存新增 -->
    <BaseDialog title="配件库存新增" :visible.sync="addPartInfoisShow" destroyOnClose>
      <addPartInfo :formData="formData" @cancel="cancel" @addChange="addChange" />
    </BaseDialog>
  </div>
</template>

<script>
import PartInfo from './PartInfo';
import addPartInfo from './addPartInfo';
export default {
  name: 'cgrk_edit',
  components: {
    PartInfo,
    addPartInfo
  },
  props: {
    selectRow: Object
  },
  data() {
    return {
      formData: {},
      addPartInfoisShow: false,
      partInfoRow: {}
    };
  },
  mounted() {
    window.cgrk_edit = this;
    console.log('cgrk_edit mounted', this.selectRow);
    this.partInfoRow = Object.assign({}, this.selectRow);
  },
  methods: {
    // 传值打开弹窗
    getAddPartInfo(row) {
      this.formData = row;
      this.addPartInfoisShow = true;
    },
    // 新增仓库保存之后回调的值      ///////
    addChange(partInfo) {
      this.addPartInfoisShow = false;
      this.$emit('confirm', partInfo);
    },
    // 关闭弹窗
    cancel() {
      this.addPartInfoisShow = false;
    },
    confirmBtnClick() {
      this.$refs.partInfo.$refs.form.SUBMIT_FORM();
      this.$refs.partInfo.handleEditConfirm();
    },
    getEditPartInfo(partInfo) {
      console.log('表单数据', JSON.stringify(partInfo, null, 2));
      // 给父表加的数据
      this.$emit('confirm', partInfo);
    }
  }
};
</script>

<style scoped>
.btnWrap {
  position: absolute;
  left: 0px;
  bottom: 0px;
  right: 0px;
  z-index: 9;
  border-top: 1px solid rgb(233, 233, 233);
  padding: 10px 20px;
  background: rgb(255, 255, 255);
  text-align: right;
}
</style>
